package com.jic.order.controller.manage;

import com.jic.order.response.OrderGoodsResponse;
import com.jic.order.service.OrderGoodsService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: TODO
 * @author: lixuehui
 * @date: 2020/11/28 18:35
 * @Version 1.0
 */
@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
@Slf4j
@Api(value = "热销商品信息", tags = {"热销商品信息"})
@RequestMapping(value = "mHotProduct")
@RestController
public class OrderGoodsController {
    @Resource
    OrderGoodsService orderGoodsService;
    //定时任务------每天晚上23:55分执行
    @Scheduled(cron = "0 55 23 ? * *")
    public  void  getTopTenGoods(){
        System.out.println("------------热销商品查询定时任务开始-----------");
        //第一步 查询热销10条数据 获取其Id
        List<OrderGoodsResponse> queryTopTenGoodes = orderGoodsService.queryTopTenGoodes();
        //第二步 将查询出的数据，新增至 m_hot_product商品表
        queryTopTenGoodes.forEach(item ->{

            orderGoodsService.insertProductbyOrder(item);
        });
        System.out.println("------------热销商品查询定时任务结束-----------");
    }


}
